<?php
	//获得一条广告图片
	function getOneSite(){
		$ad =array(
			'<p>本文由即美说减肥网http://www.jimeishuo.com/整理发布,转载请注明:<a href="http://www.jimeishuo.com/" target="_blank">即美说减肥网</a>',
			'<p>本文由即美说瘦身网http://www.jimeishuo.com/整理发布,转载请注明:<a href="http://www.jimeishuo.com/" target="_blank">即美说瘦身网</a>',
			'<p>本文由学瘦身减肥网http://www.xueshoushen.com/整理发布,转载请注明:<a href="http://www.xueshoushen.com/" target="_blank">学瘦身减肥网</a>',
			'<p>本文由膜膜皇后http://mmhhqjd.sinaapp.com/整理发布,转载请注明:<a href="http://mmhhqjd.sinaapp.com/" target="_blank">膜膜皇后</a>',
			'<p>本文由膜膜皇后精油http://mmhhqjd.sinaapp.com/整理发布,转载请注明:<a href="http://mmhhqjd.sinaapp.com/" target="_blank">膜膜皇后精油</a>',
			'<p>本文由香草园精油http://xiangcaoyuan.sinaapp.com/整理发布,转载请注明:<a href="http://xiangcaoyuan.sinaapp.com/" target="_blank">香草园精油</a>',
			'<p>本文由香草园精油http://www.pangjiemei.com/整理发布,转载请注明:<a href="http://www.pangjiemei.com/" target="_blank">香草园精油</a>',
			'<p>本文由即美说左旋肉碱减肥网http://www.jimeishuo.com/整理发布,转载请注明:<a href="http://www.jimeishuo.com/" target="_blank">即美说左旋肉碱减肥网</a>',
			'<p>本文由网购我帮您http://wg580.sinaapp.com/整理发布,转载请注明:<a href="http://wg580.sinaapp.com/" target="_blank">网购我帮您</a>',
			'<p>本文由淘美丽http://taomeili.sinaapp.com/整理发布,转载请注明:<a href="http://taomeili.sinaapp.com/" target="_blank">淘美丽</a>',
		);
		$id = array_rand($ad);
		return $ad[$id];
	}
	/*
	*取得一条blog。
	*/
	function getOneblog(){
		global $conn;
		$sql = "SELECT a.id, a.typeid, a.arcrank, a.title, a.keywords, d.body
				FROM  `dede_archives` AS a, dede_addonarticle AS d
				WHERE a.id = d.aid
				AND a.arcrank != -2
				ORDER BY RAND( )";
		$onelog = $conn->result($sql);
		return $onelog;
	}
	//修改一个文章状态
	function update_archive($id='')
	{	
		global $conn;
		if($id != ''){
			$sql = "update `dede_archives` set `arcrank` = -2 where id = ".$id;
			printlog("sql:". $sql,"sina");
			$query = $conn->query($sql);
			return $query;
		}else{
			return false;
		}
	}
	//获取一个笑话
	function getOneJoke(){
		global $conn;
		$m= 1;
		$n = 6097;
		$rand = rand($m,$n);
		$sql = "select * from `jiaxin_joke`  limit ".$rand."  ,1";
		$query = $conn->query($sql);
		if($query){
			$onejoke = $conn->fetch_assoc($query);
		}
		return $onejoke['content'];
	}
	//获取一个广告
	function getOneAd(){
		$datafile = ROOT_PATH."/include/urls.txt";
		$f= fopen($datafile,"r");
		while (!feof($f)){
				$line = fgets($f);
				if($line != ''){
					$array[] = $line;
				}
		}
		fclose($f);
		$id = array_rand($array);
		return $array[$id];
	}
	//获取一个weibo
	function getOneMsg(){
		global $conn;
		$m= 1;
		$n = 228080;
		$rand = rand($m,$n);
		$sql = "select * from `tbl_content`  limit ".$rand."  ,1";
		$query = $conn->query($sql);
		if($query){
			$onemsg = $conn->fetch_assoc($query);
		}
		return $onemsg['content'];
	}
	/*
	*取得一个user。
	*/
	function getOneuser($site){
		global $conn;
		$sql = "SELECT * from tbl_blogusers where site='$site' ORDER BY RAND( )";
		$oneuser = $conn->result($sql);
		return $oneuser;
	}
	/*
	*取得alluser。
	*/
	function getAllusers($site){
		global $conn;
		$sql = "SELECT * from tbl_blogusers where site='$site'";
		$query = $conn->query($sql);
		if($query){
			while($oneuser = $conn->fetch_assoc($query)){
				$users[] = $oneuser;
			}
		}
		return $users;
	}
	//取得近义词
	function getRelateWord($code='u'){
		if($code == 'u'){
			$datafile = ROOT_PATH."/include/relatedu.txt";
		}else{
			$datafile = ROOT_PATH."/include/relatedg.txt";
		}
			$f= fopen($datafile,"r");
			while (!feof($f)){
				$line = fgets($f);
				if($line != ''){
					$rel = explode("\t",$line);
					$arr['find'][] = $rel[0];
					$arr['replace'][] = $rel[1];
				}
			}
		fclose($f);
		return $arr;
	}
	/*
	*Seo伪原创。
	*/
	function getSeo($body,$find, $replace){
		preg_match_all('%<p.*?>[\s\S.]*?</p>%i', $body,$matches);
		shuffle($matches[0]);
		$body = implode(" ",$matches[0]);
		$body = str_replace($find, $replace,$body);
		// $number = array('step','Step','STEP','导语','%','0','1','2','3','4','5','6','7','8','9','一','二','三','四','五','六','七','八','九','十','、');
		// $body = str_replace($number,"",$body);
		return $body;
	}
	/*
	*生成随机的字符
	*/
	function createRandStrb ()
	{	
		$s = '';
		$str = "0123456789abcdefghijklmnopqrstuvwxyz";   //   输出字符集  
		$n = 10;   //   输出串长度  
		$len = strlen($str)-1;
		for($i=0 ; $i<$n; $i++){
			$s .=  $str[rand(0,$len)];  
		}
		
		return $s;
	}
	//唐纳德算法生成随机数 m=2 n=5
	function getknuth($m,$n){
		for($i=0;$i<$n;$i++){
			if(rand() %($n-$i) <$m){
				$rand[] = $i; 
				$m--;
			}
		}
		return $rand;
	}
?>
